package com.hdculture.simple.expensemanager.premium;

import com.hdculture.simple.expensemanager.premium.R;

import android.app.Activity;
import android.widget.*;
import android.util.Log;
import android.view.*;
import android.os.Bundle;
import android.content.*;
import android.graphics.drawable.GradientDrawable;

public class LoginActivity extends Activity {
    /** Called when the activity is first created. */
	EditText passwordText;
	Button loginButton;
	CoreDBAdapter dbAdapter;
	String tag="LoginActivity";
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.login);
        dbAdapter = new CoreDBAdapter(LoginActivity.this);
        Log.i(tag,"DB Connection Open");
        dbAdapter.open();
        passwordText = (EditText)findViewById(R.id.passwordText);
        loginButton = (Button)findViewById(R.id.loginButton);
        loginButton.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				//Password verification code here...
				if(dbAdapter.verifyPassword(passwordText.getText().toString())==true){
				passwordText.setText("");
				Intent i = new Intent(LoginActivity.this,MainActivity.class);
				startActivity(i);
				dbAdapter.close();
				Log.i(tag,"DB Connection Closed");
				finish();
				
				}else{
					passwordText.setText("");
					Toast.makeText(LoginActivity.this,"Incorrect Password!",500).show();
				}
			}
		});
    }
    
}